{% macro pagination_widget(pagination, endpoint, fragment = "") %}
<ul class="pagination">
    <li {% if not pagination.has_prev %} class="disabled" {% endif %}>
        <a href="{% if pagination.has_prev %}{{ url_for(endpoint, page = pagination.page-1, **kwargs) }}{{ fragment }}{% else %}#{% endif %}">&laquo;</a>
    </li>

    {% for page in pagination.iter_pages() %}
        {% if page %}
            {% if page == pagination.page %}
                <li class="active"><a href="{{ url_for(endpoint, page = page, **kwargs) }}{{ fragment }}">{{ page }}</a></li>
            {% else %}
                <li><a href="{{ url_for(endpoint, page = page, **kwargs) }}{{ fragment }}">{{ page }}</a></li>
            {% endif %}
        {% else %}
            <li class="disabled"><a href="#">&hellip;</a> </li>
        {% endif %}
    {% endfor %}

    <li {% if not pagination.has_next %} class="disabled" {% endif %}>
        <a href="{% if pagination.has_next %}{{ url_for(endpoint, page = pagination.page+1, **kwargs) }}{{ fragment }}{% else %}#{% endif %}">&raquo;</a>
    </li>
</ul>
{% endmacro %}